﻿<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:views="clr-namespace:RSSFeedReader.Views"
        xmlns:res="clr-namespace:RSSFeedReader.Resources;assembly=RSSFeedReader.Resources"
        xmlns:converter="clr-namespace:RSSFeedReader.Converters"
        xmlns:webUtility="clr-namespace:RSSFeedReader.AttachedProperties"
        x:Class="RSSFeedReader.Views.MainView"
        WindowStartupLocation="CenterScreen"
        Title="{x:Static res:Strings.ApplicationName}"
        MinWidth="200"
        MinHeight="200"
        DataContext="{Binding Main, Source={StaticResource Locator}}">
    <Window.Resources>
        <!--CopyLink ContextMenu-->
        <ContextMenu x:Key="CopyLinkCtxMenu">
            <MenuItem Header="{x:Static res:Strings.CopyLinkCtxMenu_Header}"
                      Command="{Binding Path=CopyLinkCommand}" />
        </ContextMenu>
        <converter:ChannelImageConverter x:Key="ChannelImageConverter" />
        <!-- Allows a KeyBinding to be associated with a command defined in the View Model  -->
        <SolidColorBrush x:Key="MainViewContentHeaderBackGround"
                         Color="#FF000000" />
        <LinearGradientBrush x:Key="MainViewContentHeaderShiny"
                             EndPoint="0.5,1"
                             StartPoint="0.5,0">
            <GradientStop Color="#7FFFFFFF"
                          Offset="0" />
            <GradientStop Color="#00FFFFFF"
                          Offset="1" />
        </LinearGradientBrush>
    </Window.Resources>
    <Window.InputBindings>
        <KeyBinding Key="X"
                    Modifiers="Control"
                    Command="{Binding ExitCommand}" />
        <KeyBinding Key="N"
                    Modifiers="Control"
                    Command="{Binding AddNewFeedCommand}" />
        <KeyBinding Key="F5"
                    Command="{Binding SyncChannelCommand}" />
        <KeyBinding Key="F5"
                    Modifiers="Control"
                    Command="{Binding SyncAllChannelsCommand}" />
        <KeyBinding Key="Delete"
                    Command="{Binding DeleteChannelCommand}" />
        <KeyBinding Key="Delete"
                    Modifiers="Shift"
                    Command="{Binding DeleteAllChannelsCommand}" />
        <KeyBinding Key="I"
                    Modifiers="Control"
                    Command="{Binding ImportFeedsCommand}" />
        <KeyBinding Key="E"
                    Modifiers="Control"
                    Command="{Binding ExportFeedsCommand}" />
        <KeyBinding Key="F2"
                    Command="{Binding CurrentChannel.RenameChannelCommand}" />
        <KeyBinding Key="Enter"
                    Modifiers="Alt"
                    Command="{Binding CurrentChannel.ChannelPropertiesCommand}" />
    </Window.InputBindings>
    <Border x:Name="mainBorder">
        <DockPanel x:Name="mainDockPanel">
            <Menu DockPanel.Dock="Top">
                <!--Background="{x:Null}"
              Foreground="#FFFFFFFF"
              Style="{DynamicResource MenuStyle}">-->
                <MenuItem Header="{x:Static res:Strings.MainView_FileMenuItem}">
                    <!--Style="{DynamicResource MenuItemStyle}"
                Background="{x:Null}"
                      Foreground="#FFFFFFFF">-->
                    <MenuItem x:Name="_addFeedMenuItem"
                              Header="{x:Static res:Strings.MainView_AddFeedMenuItem}"
                              Command="{Binding Path=AddNewFeedCommand}"
                              InputGestureText="Ctrl+N" />
                    <!--Background="{DynamicResource MenuBackground}" />-->
                    <!--Foreground="#FFFFFFFF" />-->
                    <MenuItem x:Name="_deleteFeedMenuItem"
                              Header="{x:Static res:Strings.MainView_DeleteFeedMenuItem}"
                              InputGestureText="Del"
                              Command="{Binding Path=DeleteChannelCommand}" />
                    <!--Foreground="#FFFFFFFF"/>-->
                    <!--Background="{x:Null}"
                      Foreground="#FFFFFFFF">-->
                    <MenuItem x:Name="_deleteAllFeedsMenuItem"
                              Header="{x:Static res:Strings.MainView_DeleteAllFeedsMenuItem}"
                              InputGestureText="Shift+Del"
                              Command="{Binding Path=DeleteAllChannelsCommand}" />
                    <!--Background="{x:Null}"
                      Foreground="#FFFFFFFF">-->
                    <Separator />
                    <!--Background="{DynamicResource MenuBackground}" />-->
                    <!--Foreground="#FFFFFFFF" />-->
                    <MenuItem x:Name="_exitMenuItem"
                              Header="{x:Static res:Strings.MainView_ExitMenuItem}"
                              Command="{Binding Path=ExitCommand}"
                              InputGestureText="Ctrl+X" />
                    <!--Background="{x:Null}"
                      Foreground="#FFFFFFFF">-->
                </MenuItem>
                <MenuItem Header="{x:Static res:Strings.MainView_Tools}">
                    <!--Background="{x:Null}"
                      Foreground="#FFFFFFFF">-->
                    <MenuItem x:Name="_exportMenuItem"
                              Header="{x:Static res:Strings.MainView_ExportMenuItem}"
                              Command="{Binding Path=ExportFeedsCommand}"
                              InputGestureText="Ctrl+E" />
                    <!--Background="{x:Null}"
                      Foreground="#FFFFFFFF">-->
                    <MenuItem x:Name="_importMenuItem"
                              Header="{x:Static res:Strings.MainView_ImportMenuItem}"
                              Command="{Binding Path=ImportFeedsCommand}"
                              InputGestureText="Ctrl+I" />
                    <!--Background="{x:Null}"
                      Foreground="#FFFFFFFF">-->
                    <Separator />
                    <!--Background="{DynamicResource MenuBackground}" />-->
                    <!--Foreground="#FFFFFFFF" />-->
                    <MenuItem x:Name="_syncFeedMenuItem"
                              Header="{x:Static res:Strings.MainView_SyncFeedMenuItem}"
                              InputGestureText="F5"
                              Command="{Binding Path=SyncChannelCommand}" />
                    <!--Background="{x:Null}"
                      Foreground="#FFFFFFFF">-->
                    <MenuItem x:Name="_syncAllFeedsMenuItem"
                              Header="{x:Static res:Strings.MainView_SyncAllFeedsMenuItem}"
                              InputGestureText="Ctrl+F5"
                              Command="{Binding Path=SyncAllChannelsCommand}" />
                    <!--Background="{x:Null}"
                      Foreground="#FFFFFFFF">-->
                    <MenuItem x:Name="_manageFeedsMenuItem"
                              Header="{x:Static res:Strings.MainView_ManageFeedsMenuItem}"
                              Command="{Binding Path=ManageFeedsCommand}" />
                    <Separator />
                    <MenuItem x:Name="_logMenuItem"
                              Header="{x:Static res:Strings.MainView_ViewErrorLog}"
                              Command="{Binding Path=ViewErrorLogCommand}" />
                </MenuItem>
            </Menu>
            <Grid x:Name="_mainGrid">
                <!-- Add additional content here -->
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="280" />
                    <ColumnDefinition Width="300" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <views:ChannelView DataContext="{Binding}"
                                   Grid.RowSpan="2"
                                   Background="{x:Null}"
                                   x:Name="_ChannelView">
                </views:ChannelView>
                <GridSplitter HorizontalAlignment="Right"
                              VerticalAlignment="Stretch"
                              Width="3"
                              Grid.RowSpan="2"
                              Background="#FFFFFFFF"
                              IsTabStop="False" />
                <views:PostView DataContext="{Binding}"
                                Grid.Column="1"
                                Grid.RowSpan="2" />
                <GridSplitter HorizontalAlignment="Right"
                              VerticalAlignment="Stretch"
                              Grid.Column="1"
                              Width="3"
                              Grid.RowSpan="2"
                              Background="#FFFFFFFF"
                              IsTabStop="False" />
                <Grid x:Name="_contentGrid"
                      Grid.Column="2"
                      Grid.RowSpan="1">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Rectangle Stroke="{x:Null}"
                               Fill="{DynamicResource MainViewContentHeaderBackGround}"
                               Grid.ColumnSpan="2"
                               Grid.RowSpan="3" />
                    <Rectangle Stroke="{x:Null}"
                               Margin="0,-1,0,36"
                               Fill="{DynamicResource MainViewContentHeaderShiny}"
                               Grid.ColumnSpan="2"
                               Grid.RowSpan="3" />
                    <TextBlock x:Name="_feedChannelTextBlock"
                               Margin="5,0,0,0"
                               HorizontalAlignment="Left"
                               VerticalAlignment="Top"
                               FontSize="14"
                               Foreground="#FFFFFFFF"
                               Text="{Binding Path=CurrentChannel.Title}">
                            <TextBlock.Style>
                                <Style>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Path=CurrentChannel.SelectedPost.Link}"
                                                     Value="{x:Null}">
                                            <Setter Property="TextBlock.Visibility"
                                                    Value="Collapsed" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBlock.Style></TextBlock>
                    <TextBlock Height="20"
                               x:Name="_linkTextBlock"
                               Grid.Row="2"
                               Margin="5,0,0,0"
                               HorizontalAlignment="Left"
                               VerticalAlignment="Bottom"
                               ToolTip="{x:Static res:Strings.BrowserView_ViewPostInBrowserHyperLinkToolTip}"
                               ContextMenu="{StaticResource CopyLinkCtxMenu}">
                        <TextBlock.Style>
                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Path=CurrentChannel.SelectedPost.Link}"
                                                 Value="{x:Null}">
                                        <Setter Property="TextBlock.Visibility"
                                                Value="Collapsed" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                        <Hyperlink Command="{Binding Path=OpenInBrowserCommand}">
                            <InlineUIContainer>
                    			<TextBlock Text="{x:Static res:Strings.BrowserView_ViewPostInBrowserHyperLinkText}"
                                           FontWeight="Bold"
                                           Foreground="#FFA7A7A7"
                                           TextDecorations="Underline" />
                    		</InlineUIContainer>
                        </Hyperlink>
                    </TextBlock>
                    <TextBlock x:Name="_feedTitleTextBlock"
                               HorizontalAlignment="Center"
                               VerticalAlignment="Center"
                               FontSize="20"
                               Foreground="#FFFFFFFF"
                               TextDecorations="Underline"
                               TextWrapping="Wrap"
                               Grid.Row="1">
                        <TextBlock.Style>
                                <Style>
                                    <Setter Property="TextBlock.Text"
                                            Value="{Binding Path=CurrentChannel.SelectedPost.Title}" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Path=CurrentChannel.SelectedPost.Link}"
                                                     Value="{x:Null}">
                                            <Setter Property="TextBlock.Text"
                                                    Value="{x:Static res:Strings.MainView_NoPostsSelected}" />
                                        </DataTrigger>    
                                    </Style.Triggers>
                                </Style>
                        </TextBlock.Style>
                    </TextBlock>
                    <TextBlock x:Name="_feedPublishedDateTextBlock"
                               Margin="0,0,5,0"
                               HorizontalAlignment="Right"
                               VerticalAlignment="Top"
                               FontSize="12"
                               Foreground="#FFFFFFFF"
                               Text="{Binding Path=CurrentChannel.SelectedPost.PublishedDate}"
                               Grid.Column="1" />
                    <Image x:Name="_feedImage"
                           HorizontalAlignment="Right"
                           Margin="0,0,5,5"
                           VerticalAlignment="Bottom"
                           MaxHeight="50"
                           MaxWidth="200"
                           Grid.Column="1"
                           Grid.Row="1">
                        <Image.Style>
                            <Style>
                                <Setter Property="Image.Source"
                                        Value="{Binding Path=CurrentChannel.ImageUrl, Converter={StaticResource ChannelImageConverter}}" />
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Path=CurrentChannel.ImageUrl}"
                                                 Value="{x:Null}">
                                        <Setter Property="Image.Visibility"
                                                Value="Collapsed" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Image.Style>
                    </Image>
                </Grid>
                <WebBrowser Grid.Row="1"
                            Grid.Column="2"
                            Name="webBrowser"
                            webUtility:WebBrowserUtility.BindableSource="{Binding Path=CurrentChannel.SelectedPost.Link}"
                            Navigated="WebBrowserNavigated" />
            </Grid>
        </DockPanel>
    </Border>
</Window>
